package com.coocaa.aries.core.base.builder;


import com.coocaa.aries.core.tool.json.JsonUtil;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author bijiahao
 * @date : 2019/10/11.
 * @description
 */
public class ExceptionBuilder {
    /**
     * 保持字段顺序
     */
    private LinkedHashMap info;

    private ExceptionBuilder() {
        this.init();
    }

    public static ExceptionBuilder.Builder newBuilder() {
        return new Builder();
    }

    /*************** ===私有方法=== ********************* ===start=== ***************************************/


    private void init() {
        this.info = new LinkedHashMap();
    }

    public static final class Builder {
        private ExceptionBuilder exceptionBuilder;

        public Builder() {
            this.exceptionBuilder = new ExceptionBuilder();
        }

        public ExceptionBuilder.Builder withUrl(String url) {
            this.exceptionBuilder.info.put("url", url);
            return Builder.this;
        }

        public ExceptionBuilder.Builder withMethod(String method) {
            this.exceptionBuilder.info.put("method", method);
            return Builder.this;
        }

        public ExceptionBuilder.Builder withCalledServiceName(String calledServiceName) {
            this.exceptionBuilder.info.put("calledServiceName", calledServiceName);
            return Builder.this;
        }

        public ExceptionBuilder.Builder withOpParams(Object opParams) {
            this.exceptionBuilder.info.put("opParams", JsonUtil.obj2Json(opParams));
            return Builder.this;
        }

        public ExceptionBuilder.Builder withDetailMsg(String detailMsg) {
            this.exceptionBuilder.info.put("detailMsg", detailMsg);
            return Builder.this;
        }

        public Map build() {
            return this.exceptionBuilder.info;
        }
    }
}
